<%--
  Created by IntelliJ IDEA.
  User: 10843
  Date: 2021/6/10
  Time: 10:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<script src="${pageContext.request.contextPath}/js/jquery-3.5.1.js"></script>
<body>
    <%--ajax实现异步交互--%>
    <button id="btn1">ajax实现异步交互</button>
    <script>
        $("#btn1").click(function () {
            let url = "${pageContext.request.contextPath}/user/ajaxRequest";
            let data = '[{"id":1,"username":"欧阳钊"},{"id":2,"username":"王德来"}]';
            $.ajax({
                type:'POST',
                url: url,
                data: data,
                contentType: 'application/json;charset=utf-8',
                success(resp){
                    alert(JSON.stringify(resp));
                }
            })
        })
    </script>

</body>
</html>
